var express = require('express');
var config = require('./build/config/index');

var port = process.env.PORT || config.dev.port;

var app = express();

var router = express.Router();

router.get('/', function (req, res, next) {
  req.url = '/index.html';
  next();
});

app.use(router);

var appData = require('./data.json');
var cancelSignUp = appData.cancelSignUp;
var getActivitieUsers = appData.getActivitieUsers;
var getSignUpTimes = appData.getSignUpTimes;
var searchSignUp = appData.searchSignUp;
var submitSignln = appData.submitSignln;
var submitSignUp = appData.submitSignUp;
var apiRoutes = express.Router();
apiRoutes.get('/cancelSignUp', function (req, res) {
  res.json({
    data: cancelSignUp
  });
});

apiRoutes.get('/getActivitieUsers', function (req, res) {
  res.json({
    data: getActivitieUsers
  });
});

apiRoutes.get('/getSignUpTimes', function (req, res) {
  res.json({
    data: getSignUpTimes
  });
});
apiRoutes.get('/searchSignUp', function (req, res) {
  res.json({
    data: searchSignUp
  });
});

apiRoutes.get('/submitSignln', function (req, res) {
  res.json({
    errno: 0,
    data: submitSignln
  });
});

apiRoutes.get('/submitSignUp', function (req, res) {
  res.json({
    errno: 0,
    data: submitSignUp
  });
});
app.use('/api', apiRoutes);

app.use(express.static('./dist'));
module.exports = app.listen(port, function (err) {
  if (err) {
    console.log(err);
    return;
  }
  console.log('Listening at http://localhost:' + port + '\n');
});
